package com.lwb.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lwb.commonutils.Row;
import com.lwb.eduservice.entity.EduCourse;
import com.lwb.eduservice.entity.EduTeacher;
import com.lwb.eduservice.service.EduCourseService;
import com.lwb.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacher-front")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    //1. 分页查询讲师
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public Row getTeacherFrontList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> teacherPage = new Page<>(page,limit);
        Map<String,Object> map = eduTeacherService.getTeacherFrontList(teacherPage);
        return Row.SUCCESS().data(map);
    }

    //2. 讲师详情的功能
    //2.1 根据id查询讲师信息
    @GetMapping("getTeacherFrontInfo/{id}")
    public Row getTeacherFrontInfo(@PathVariable String id){
        //1. 根据讲师id查询讲师信息
        EduTeacher teacher = eduTeacherService.getById(id);

        //2. 根据讲师id查询讲师所属的课程
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id",id);
        List<EduCourse> list = eduCourseService.list(queryWrapper);

        return Row.SUCCESS().data("teacher",teacher).data("list",list);
    }
}

